from appium import webdriver

import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

desired_caps = dict()
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '111'
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# 1》使用隐式等待,找到元素,立即执行下一步,没有找到,报错
# driver.implicitly_wait(10)
# 通过xpath定位返回按钮，点击
# print('准备点击返回按钮')
# driver.find_element(By.XPATH, "//*[@content-desc='收起']").click()
# print('我点完了')

# 2》显示等待，针对单个元素起作用
# 格式：WebDriverWait(driver,等待时长,查找频率).until(lambda x: x.find_element(By.xx,''))
print('准备点击返回按钮')
backButton = WebDriverWait(driver, 5, 1).until(lambda x: x.find_element(By.XPATH, "//*[@content-desc='收起']"))
backButton.click()
print('我点完了')

time.sleep(5)

driver.quit()
